package com.heatingcharge.common.util;

import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.springframework.http.HttpStatus;

/**
 * Created with IntelliJ IDEA.
 * Description: heating_charge_server
 * User: Devin
 * Date: 2019-06-28
 * Time: 11:17
 */
@Data
@ToString
@Accessors(chain = true)
public class R {
    private static final long serialVersionUID = 1L;


    private int code = 200;
    private String msg;
    private Object data;

    public static R ok() {
        R r = new R();
        r.setMsg("操作成功");
        return r;
    }

    public static R ok(Object data) {
        R r = new R();
        r.setMsg("操作成功");
        r.setData(data);
        return r;
    }

    public static R error() {
        return error(ResponseCodeEnum.OPERATE_FAIL.getCode(),ResponseCodeEnum.OPERATE_FAIL.getMessage());
    }
    public static R error(ResponseCodeEnum responseCodeEnum) {
        return error(responseCodeEnum.getCode(), responseCodeEnum.getMessage());
    }

    public static R error(String msg) {
        return error(HttpStatus.INTERNAL_SERVER_ERROR.value(), msg);
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }
}
